home *** CD-ROM | disk | FTP | other *** search
/ Power Hacker 2003 / Power_Hacker_2003.iso / Exploit and vulnerability / w00w00 / w00os / shared / src / c1.asm next >
Encoding:
Assembly Source File  |  1998-12-31  |  1.8 KB  |  89 lines

  1. ;--------------------------------------------------
  2. ; convert an 32-bit uint into ascii (4 digits)
  3. ;--------------------------------------------------
  4.  
  5. hex2int: /* char **ptr, int *intValue */
  6.    int hexValue;
  7.    int numChars = 0;
  8.  
  9.    *intValue = 0;
  10.  
  11.    while (**ptr)
  12.    {
  13.       hexValue = hex(**ptr);
  14.  
  15.       if (hexValue >= 0)
  16.       {
  17.          *intValue = (*intValue << 4) | hexValue;
  18.          numChars++;
  19.       }
  20.       else break;
  21.  
  22.       (*ptr)++;    
  23.    }
  24.  
  25.    return (numChars);
  26.  
  27.  
  28. ;--------------------------------------------------
  29. ; convert an 8-bit hex char into a 8-bit ascii #
  30. ;--------------------------------------------------
  31.  
  32. hex2char:
  33.  
  34.   if ((ch >= 'a') && (ch <= 'f')) return (ch-'a'+10);
  35.   else if ((ch >= 'A') && (ch <= 'F')) return (ch-'A'+10);
  36.   else if ((ch >= '0') && (ch <= '9')) return (ch-'0');
  37.  
  38.   return (-1);
  39.  
  40.  
  41. ;--------------------------------------------------
  42. ; convert a string from memory into a hex string
  43. ;--------------------------------------------------
  44.  
  45. mem2hex:
  46.    int i; 
  47.    unsigned char ch;
  48.  
  49.    char hexchars[] = "0123456789abcdef";
  50.  
  51.    if (may_fault) mem_fault_routine = set_mem_err;
  52.  
  53.    for (i = 0; i < count; i++)
  54.    {
  55.       ch = get_char(mem++);
  56.  
  57.       if (may_fault && mem_err) return (buf);
  58.       *buf++ = hexchars[ch >> 4], *buf++ = hexchars[ch % 16];
  59.    }
  60.  
  61.    *buf = 0;
  62.  
  63.    if (may_fault) mem_fault_routine = NULL;
  64.    return(buf);
  65.  
  66.  
  67. ;--------------------------------------------------
  68. ; convert a string from memory into a hex string
  69. ;--------------------------------------------------
  70.  
  71. hex2mem:
  72.    int i;
  73.    unsigned char ch;
  74.  
  75.    if (may_fault) mem_fault_routine = set_mem_err;
  76.  
  77.    for (i = 0; i < count; i++)
  78.    {
  79.       ch = hex(*buf++) << 4, ch += hex(*buf++);
  80.  
  81.       set_char (mem, ch), mem++;
  82.       if (may_fault && mem_err) return (mem);
  83.    }
  84.  
  85.    if (may_fault) mem_fault_routine = NULL;
  86.    return(mem);
  87.  
  88.  
  89.